<%@ page language="java" contentType="text/html;charset=UTF-8" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html" %>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
<%@ taglib prefix="logic" uri="http://struts.apache.org/tags-logic" %>
<%@ taglib prefix="nested" uri="http://struts.apache.org/tags-nested" %>

<html>
<head>
<title>메세지</title>
<link href="<%=request.getContextPath()%>/common/css/message.css" type="text/css" rel="stylesheet"/>
</head>
<body onload="resizeWindow()">
<table style="width: 350px;vertical-align: top;" cellpadding="0" cellspacing="0">
	<tr>
		<td style="width: 350px;height: 20px;vertical-align: top;">
			<%@ include file="./messagenavi.jsp" %>
		</td>
	</tr>
	<tr>
			<html:form action="/message">			
		<td style="text-align: center;vertical-align: top;border: 1px solid #355884;border-top:1px solid #8db1dd;border-left:1px solid #8db1dd;">
			<!-- 리스트 표시 -->
			<table style="width: 350px;" cellpadding="0" cellspacing="0">
				<tr style="height: 20px;">
					<td class="msgListTd1" style="width: 30px;">분류</td>
					<td class="msgListTd1" style="width: 80px;">보낸이</td>
					<td class="msgListTd1" >내용</td>
					<td class="msgListTd1" style="width: 60px;">보낸날짜</td>
				</tr>
				
				<logic:empty name="messageForm" property="list">
					<tr>
						<td colspan="4" class="msgListTd1">메세지가 없습니다.</td>
					</tr>
				</logic:empty>
				
				<logic:notEmpty  name="messageForm" property="list">
					<logic:iterate id="msg" name="messageForm" property="list">
						<input type="hidden" name="category" value="<bean:write name="msg" property="category"/>"/>
						<tr>
							<td style="text-align: center;">
								<input type="checkbox" name="checkMno" value="<bean:write name="msg" property="mno"/>">
								</td>
							<td style="text-align: center;"><bean:write name="msg" property="send" /></td>
							<td style="text-align: left;">
								<a href="message.do?method=readMessage&mno=<bean:write name="msg" property="mno"/>">
							<logic:lessThan value="1" name="msg" property="behold">
								<img src="<%=request.getContextPath() %>/common/image/message_c.gif" border="0"/>
							</logic:lessThan>
							<logic:greaterThan value="0" name="msg" property="behold">
								<img src="<%=request.getContextPath() %>/common/image/message_o.gif" border="0"/>
							</logic:greaterThan>
							
								<bean:write name="msg" property="message" />
								</a>
							</td>
							<td><bean:write name="msg" property="senddate" /></td>
						</tr>
					</logic:iterate>
					<!-- 페이징 -->
					<tr>
						<td colspan="4" style="border-top: 1px dotted #8db1dd; ">
							<%
								String section = request.getParameter("section");								
								
								if(section.equals("list"))
								{
									%>
									<jsp:include page="../board/pager.jsp">
										<jsp:param name="url" value="message.do?method=receive&category=list"/>
									</jsp:include>
									<%
								}
								else
								{
									%>
									<jsp:include page="../board/pager.jsp">
										<jsp:param name="url" value="message.do?method=receive&category=save"/>
									</jsp:include>
									<%
								}
							%>
							
						</td>
					</tr>
				</logic:notEmpty>				
				<tr><td colspan="4" style="text-align: right;padding-right: 5px;">
					<logic:equal value="save" name="messageForm" property="category">
						<html:link href="javascript: remove('deleteMessage');">[삭제]</html:link>
					</logic:equal>
					<logic:notEqual value="save" name="messageForm" property="category">
						<html:link href="javascript: saveCheck();">[보관]</html:link>
						<html:link href="javascript: remove('deleteMessage');">[삭제]</html:link>
					</logic:notEqual>						
				</td></tr>

			<input type="hidden" name="method" value="saveMessage"/>
			<input type="hidden" name="messageForm" value="<bean:write name="messageForm" property="category"/>"/>
			</table>

		</td>
			</html:form>
	</tr>
	<tr><td style="text-align: right;padding-right: 5px;">
			<html:link href="javascript:  window.close();">[닫기]</html:link></td>
	</tr>
</table>
</body>
</html>

<script type="text/javascript">

	//쪽지 저장
	function saveCheck(){
	var checkMnos = document.getElementsByName('checkMno');
		for(var i =0;i<checkMnos.length;i++){
			if(checkMnos[i].checked){
				if(confirm("선택한 쪽지를 저장하시겠습까?")){
					messageForm.submit();					
				}
				return;
			}
			/*
			else{
				alert("저장할 쪽지를 선택하시오");
				return;
			}
			*/	
		}	
		for(var j=0;j<checkMnos.length;j++){
			if(checkMnos[j].checked==false){
				alert("저장할 쪽지를 선택하시오");
				return;
			}
		}						
	}
	
	//쪽지 삭제
	function remove(m){
		var checkMnos = document.getElementsByName('checkMno');		
		for(var i=0; i<checkMnos.length;i++){			
			if(checkMnos[i].checked){
				if(confirm("선택한 쪽지를 삭제하시겠습니까?")){
					var method = document.getElementById('method');
					method.value = m;		
					messageForm.submit();	
				}
				return;
			}
			/*			
			else{
				alert("삭제할 쪽지를 선택하시오");
				return;
			}
			*/
		}
		for(var j=0;j<checkMnos.length;j++){
			if(checkMnos[j].checked==false){
				alert("삭제할 쪽지를 선택하시오");
				return;
			}
		}						
	}
</script>